Skip to content

feat: fmt-style tracepoints with compile-time validated formats#35

Merged
Jo5ta merged 6 commits into
mainfrom
feat/fmt
Jul 11, 2026
Merged

feat: fmt-style tracepoints with compile-time validated formats#35
Jo5ta merged 6 commits into
mainfrom
feat/fmt

Conversation

@Jo5ta

@Jo5ta Jo5ta commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Stack 6/7 — based on the export PR.

CLLTK_TRACEPOINT_FMT(buffer, "loaded {} in {}ms", name, ms) — std::format-style tracepoints for C++20, validated at compile time via a never-executed consteval check against std::format_string, so a malformed format or argument mismatch is a compile error. Runtime cost identical to printf tracepoints (same varargs core, refactored to a shared va_list path).

  • Writer: meta entry type 5; C++20 only, gated on __cpp_lib_format, kernel stub static-asserts with a clear message.
  • Decoders: python renders via str.format, C++ via std::vformat with a custom formatter wrapper over decoded arguments (avoids combinatorial visit instantiation).
  • Integrated: example fmt_cpp, unit + integration tests, golden fixtures (LE and BE) with exact expected messages, docs.

Version 1.6.0 (new meta entry type — layout addition).

Jo5ta added 6 commits July 11, 2026 01:14
CLLTK_TRACEPOINT_FMT(buffer, "loaded {} in {}ms", name, ms) accepts
C++20 std::format placeholders. Validation happens at compile time
through a never-executed call to a helper taking std::format_string,
whose consteval constructor checks the literal against the argument
types - stronger than the printf attribute. Argument encoding is
unchanged (the library types arguments independently of format syntax);
the new meta entry type 5 only marks the syntax for decoders.

The varargs serializer is refactored around a va_list core so fmt
tracepoints get an entry point without the printf format attribute
({} strings must not be checked as printf formats). A char* argument
is always recorded as a string - {} has no printf %p/%s ambiguity.
C and kernel: not available (no compile-time {} validation exists
there); the macro fails with a static assert.

Signed-off-by: Jo5ta <jo5ta@mail.de>
Meta entry type 5 renders through the decoders' native {} formatters:
python str.format, C++ std::vformat. Arguments decode with the
existing type-array machinery including foreign-endian swapping; the
printf/ffi path is never touched for fmt entries. Formatting errors
degrade to the raw format string instead of failing the decode.

The C++ implementation wraps each decoded value in a small type with a
custom std::formatter that forwards the format spec, avoiding the
combinatorial std::visit-into-vformat instantiation blowup a naive
variant approach causes.

Signed-off-by: Jo5ta <jo5ta@mail.de>
Meta type mapping unit tests cover types 3-5. The integration test
compiles, runs, and decodes fmt tracepoints including format specs
({:x}, {:.2f}). Golden 1.6.0 fmt fixtures for aarch64 little endian
and s390x big endian validate both decoders against frozen files; the
generator gains a C++ writer that is skipped gracefully when
regenerating fixtures for versions without fmt support. The python
test harness target builds as C++20 (required by fmt tracepoints;
matches the examples). New example fmt_cpp shows usage including the
char*-as-string rule.

Signed-off-by: Jo5ta <jo5ta@mail.de>
README usage, file specification meta type 5, technical documentation
of validation and rendering, AGENTS.md gotchas. New meta type is a
file layout change: minor bump.

Signed-off-by: Jo5ta <jo5ta@mail.de>
Base automatically changed from feat/export to main July 11, 2026 09:44
@Jo5ta Jo5ta merged commit 0cb2fb8 into main Jul 11, 2026
7 checks passed
@Jo5ta Jo5ta deleted the feat/fmt branch July 11, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant